/* eslint-disable import/no-anonymous-default-export */
import {
    OrderList, list, sendOrder, orderPublishCancel,orderPublishOrderNum,passAudit,
    dispatchList,changeDispatchOrderStatus,changeDispatchOrderNum,dispatchOrderApplyList,dispatchOrderCancel,publishOrderCancel
} from '../services/orderApi';
export default {
    state: {
        data: [],
        listData: [],
        sendOrderData: [],
        dispatchData:[],
        applyData:[]
    },
    effects: {
        async OrderList(params) {

            const response = await OrderList(params)

            if (response.code === 200) {
                this.saveOrderInfo({
                    data: response.data,

                })
            }
        },
        async list(params) {

            const response = await list(params)

            if (response.code === 200) {
                this.saveList({
                    listData: response.data.records,

                })
            }
        },
        async sendOrder(params) {

            const response = await sendOrder(params)

            if (response.code === 200) {
                this.saveSendOrder({
                    sendOrderData: response.data,

                })
            }
        },
        async orderPublishCancel(params) {

            const response = await orderPublishCancel(params)

            if (response.code === 200) {
                this.saveOrderPublishCancel({
                    orderPublishCancelData: response.data,

                })
            }
        },

        async orderAuditPass(params) {
            await passAudit(params)
        },

        async orderPublishOrderNum(params) {
            const response = await orderPublishOrderNum(params)
            if (response.code === 200) {
                this.saveOrderPublishCancel({
                    orderPublishCancelData: response.data,

                })
            }
        },
        async changeDispatchOrderNum(params) {
            const response = await changeDispatchOrderNum(params)

        },
        async dispatchCancel(params) {
            return  await dispatchOrderCancel(params)

        },    async publishCancel(params) {
            return  await publishOrderCancel(params)

        },
        async dispatchList(params) {

            const response = await dispatchList(params)

            if (response.code === 200) {
                this.saveDispatchOrder({
                    dispatchData: response.data,

                })
            }
        },

        async dispatchOrderApplyList(params) {

            const response = await dispatchOrderApplyList(params)

            if (response.code === 200) {
                this.saveDispatchApplyData({
                    applyData: response.data,

                })
            }
        },

        async changeDispatchOrderStatus(params) {
            const response = await changeDispatchOrderStatus(params)
        },



    },
    reducers: {
        saveOrderInfo(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveList(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveSendOrder(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveDispatchOrder(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveDispatchApplyData(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveOrderPublishCancel(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
    }
}